<template>
  <Form :form="form">
    <SchemaField :schema="schema" />
    <Submit
      @submit="onSubmit"
      @click="handleClick"
      @submitSuccess="handleSubmitSuccess"
      @submitFailed="handleSubmitFailed"
      >提交</Submit
    >
  </Form>
</template>

<script lang="ts">
import { createForm } from '@formily/core'
import { createSchemaField, FormProvider } from '@formily/vue'
import { Form, Switch, Submit, FormItem } from '@formily/vxe-table/src/index'

const schema = {
  type: 'object',
  properties: {
    switch: {
      type: 'boolean',
      title: '开关',
      required: true,
      'x-decorator': 'FormItem',
      'x-component': 'Switch',
      'x-component-props': {
        openLabel: '是',
        closeLabel: '否',
      },
    },
  },
}

const form = createForm()
const { SchemaField } = createSchemaField({
  components: {
    FormItem,
    Switch,
  },
})

export default {
  components: { FormProvider, SchemaField, Submit, Form },
  data() {
    return {
      form,
      schema,
    }
  },
  methods: {
    onSubmit(value) {
      console.log('onSubmit', value)
    },
    handleClick(value) {
      console.log('handleClick', value)
    },
    handleSubmitSuccess(value) {
      console.log('handleSubmitSuccess', value)
    },
    handleSubmitFailed(value) {
      console.error('handleSubmitFailed', value)
    },
  },
}
</script>
<style lang="scss">

</style>
